<?php

namespace app\admin\controller;

use think\facade\Session;

class Login
{
    public function login(){



        $data=input('');
        if(request()->isGet() && request()->isAjax()) {

            $admin = \app\admin\model\admin\Admin::Login($data);
            if (!empty($admin)) {
                return $this->result($admin);
            } else {
                return $this->error();
            }
        }

        return View();
    }

    /***
     * 退出登录
     */
    public function logout(){



        Session::clear();

        return redirect((string)url('Login/login')->build());
    }
    public function success($data=[],$code=200,$msg="success"){

        $msg=[
            'code'=>$code,
            'msg'=>$msg,
            'data'=>$data
        ];
        return json($msg,200);
    }


    public function error($msg="error",$data=[],$code=200){

        $msg=[
            'code'=>400,
            'msg'=>$msg,
            'data'=>$data
        ];
        return json($msg,$code);
    }

    public function result($data=[]){


        return json($data);
    }
}